package upicgame.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.*;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "user")
public class User {
	private Integer id;
	private Integer uid;
	private String name;
	private String password;
	private String email;
	private String phone;
	private String address;
	private String userType;
	private String img;
	private double money;

	private Set<CartItem> cart = new HashSet<>();

	public User() {

	}

	public User(Integer id, Integer uid, String name, String password, String email, String phone, String address,
			String userType, String img, double money, Set<CartItem> cart) {
		super();
		this.id = id;
		this.uid = uid;
		this.name = name;
		this.password = password;
		this.email = email;
		this.phone = phone;
		this.address = address;
		this.userType = userType;
		this.img = img;
		this.money = money;
		this.cart = cart;
	}

	public User(Integer id, Integer uid, String name, String password, String email, String phone, String address,
			String userType, String img, double money) {
		super();
		this.id = id;
		this.uid = uid;
		this.name = name;
		this.password = password;
		this.email = email;
		this.phone = phone;
		this.address = address;
		this.userType = userType;
		this.img = img;
		this.money = money;
	}
	public User(Integer id, Integer uid, String name, String email, double money) {
		super();
		this.id = id;
		this.uid = uid;
		this.name = name;
		this.email = email;
		this.money = money;
	}
	public User(Integer id) {
		super();
		this.id = id;
	}
	

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "uid", unique = true)
	public Integer getUid() {
		return uid;
	}

	public void setUid(Integer uid) {
		this.uid = uid;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "password")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "email", unique = true)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "phone", unique = true)
	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Column(name = "address")
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(name = "usertype")
	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	@Column(name = "img")
	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}

	@Column(name = "money")
	public double getMoney() {
		return money;
	}

	public void setMoney(double money) {
		this.money = money;
	}

	@OneToMany(targetEntity = CartItem.class,mappedBy = "user",cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@Fetch(FetchMode.JOIN)
	public Set<CartItem> getCart() {
		return cart;
	}

	public void setCart(Set<CartItem> cart) {
		this.cart = cart;
	}

	@Override
	public String toString() {
		return "User [id=" + id + ", uid=" + uid + ", name=" + name + ", password=" + password + ", email=" + email
				+ ", phone=" + phone + ", address=" + address + ", userType=" + userType + ", img=" + img + ", money="
				+ money + "]";
	}

}
